window.onload = function() {
    Vue.createApp({
        data() {
          return {
                checkboxAll:true,
                cartlist: [
                  {id:1,checkbox:true, name:'《细说PHP》', price:10, count:1},
                  {id:2,checkbox:true, name:'《细说网页制作》', price:10, count:1},
                  {id:3,checkbox:true, name:'《细说JavaScript语言》', price:10, count:1},
                  {id:4,checkbox:true, name:'《细说DOM和BOM》', price:10, count:1},
                  {id:5,checkbox:true, name:'《细说Ajax与jQuery》', price:10, count:1},
                  {id:6,checkbox:true, name:'《细说PHP2》', price:10, count:1},
                ]                  
           }
        },
        computed:{
            totalPrice(){
                  let sum = 0;
                  for(let book of this.cartlist) {
                     if(book.checkbox) {
                        sum += book.price * book.count
                     }
                     
                  }
                  return `￥${sum.toFixed(2)}`;
            },
            allSel(){
               let isCheck = this.cartlist.every(item=> item.checkbox===true)
               return isCheck
            }
        },
        mounted(){
           
        },

        methods:{
           delEvent(index){
              console.log(index)
              this.cartlist.splice(index,1)
           },
           allSelEvent() {
              this.cartlist.map(item=>{
                  item.checkbox = true
               })
           }
           
        }
      }).mount('#app')
      
 
}